package com.hui.xiao.xiaohui.view;

import android.app.Activity;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TimePicker;

import com.hui.xiao.xiaohui.R;

import java.util.Calendar;

/**
 * Created by Administrator on 2016/5/21.
 */
public class ChooseData extends Activity {
    private int year;
    private int month;
    private int day;
    private int hour;
    private int minute;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.choose_date);
        DatePicker datePicker = (DatePicker) findViewById(R.id.date_picker);
        TimePicker timePicker = (TimePicker) findViewById(R.id.time_picker);
        Calendar calendar = Calendar.getInstance();
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH);
        day = calendar.get(Calendar.DAY_OF_MONTH);
        hour = calendar.get(Calendar.HOUR);
        minute = calendar.get(Calendar.MINUTE);

        datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() {
            @Override
            public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                ChooseData.this.year = year;
                ChooseData.this.month = monthOfYear;
                ChooseData.this.day = dayOfMonth;
                showDate(year, monthOfYear, dayOfMonth, hour, minute);
            }
        });
        timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
            @Override
            public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
                ChooseData.this.hour = hourOfDay;
                ChooseData.this.minute = minute;
                showDate(year, month, day, hourOfDay, minute);
            }
        });
    }

    void showDate(int year, int month, int day, int hour, int minute) {
        EditText show = (EditText) findViewById(R.id.show);
        show.setText(String.format("你购买的日期为: %d 年 %d 月 %d 日 %d 时 %d 分", year, month, day, hour, minute));
    }
}
